package com.shop.dao.admin;

import com.shop.dao.BaseDao;
import com.shop.pajo.Admin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDapImplDao implements IAdminDao {
    @Override
    public Admin getLoginAdmin(Connection connection, String name, String password) throws SQLException {
        PreparedStatement preparedStatement=null;
        ResultSet resultSet=null;
        Admin admin=null;

        if(connection!=null){
            String sql="select * from admin where aname=? and apassword=?";
            Object[] params={name,password};

            resultSet= BaseDao.execute(connection, preparedStatement, resultSet, sql, params);
            if(resultSet.next()){
                admin=new Admin();
                admin.setId(resultSet.getInt("aid"));
                admin.setAdminName(resultSet.getString("aname"));
                admin.setAdminPassword(resultSet.getString("apassword"));
            }
        }
        BaseDao.closeResource(null,preparedStatement,resultSet);
        return admin;
    }
}
